a=int(input())
M=0
a1=a
a2=a//10
a3=a//100
a4=a//1000
a5=a%1000
a6=a%1000//10
a7=a%1000//100
a8=a%100
a9=a%100//10
a10=a%10
S=[a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]
if 999 < a < 10000:
    for y in S:
        k=0
        for i in range(1,y//2+1):
             if y%i==0:
                k += 1
        if k==1:
            M=max(M,y)
print (M)

            
